Given that __underlying_type is now available in clang, implement std::underlying_type. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@135410 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__config b/include/__config index 2610d81..0c46f76 100644 --- a/include/__config +++ b/include/__config
@@ -188,6 +188,10 @@ # define _NOEXCEPT_(x) #endif +#if __has_feature(underlying_type) +# define _LIBCXX_UNDERLYING_TYPE(T) __underlying_type(T) +#endif + // end defined(__clang__) #elif defined(__GNUC__)
diff --git a/include/type_traits b/include/type_traits index 120c270..ec12b6b 100644 --- a/include/type_traits +++ b/include/type_traits
@@ -3092,6 +3092,26 @@ #endif // __has_feature(cxx_noexcept) +#ifdef _LIBCXX_UNDERLYING_TYPE + +template <class _Tp> +struct underlying_type +{ + typedef _LIBCXX_UNDERLYING_TYPE(_Tp) type; +}; + +#else // _LIBCXX_UNDERLYING_TYPE + +template <class _Tp, bool _Support = false> +struct underlying_type +{ + static_assert(_Support, "The underyling_type trait requires compiler " + "support. Either no such support exists or " + "libc++ does not know how to use it."); +}; + +#endif // _LIBCXX_UNDERLYING_TYPE + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_TYPE_TRAITS diff --git a/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp b/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp index 126ab2c..a21120b 100644 --- a/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp +++ b/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
@@ -12,8 +12,22 @@ // underlying_type #include <type_traits> +#include <climits> int main() { -#error underlying_type is not implemented + enum E { V = INT_MIN }; + enum F { W = UINT_MAX }; + + static_assert((std::is_same<std::underlying_type<E>::type, int>::value), + "E has the wrong underlying type"); + static_assert((std::is_same<std::underlying_type<F>::type, unsigned>::value), + "F has the wrong underlying type"); + +#if __has_feature(cxx_strong_enums) + enum G : char { }; + + static_assert((std::is_same<std::underlying_type<G>::type, char>::value), + "G has the wrong underlying type"); +#endif // __has_feature(cxx_strong_enums) } diff --git a/www/type_traits_design.html b/www/type_traits_design.html index 7036a45..451fdc4 100644 --- a/www/type_traits_design.html +++ b/www/type_traits_design.html
@@ -260,7 +260,7 @@ <tr> <td><tt>underlying_type<T></tt></td> -<td bgcolor="#FF5965"><tt>__underlying_type(T)</tt></td> +<td bgcolor="#80FF80"><tt>__underlying_type(T)</tt></td> </tr> <tr>